<?php

namespace App\Console\Commands\Fy;

use App\Imports\Fy\FyRegionImport;
use App\Models\Fy\FyRegionModel;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;

class GenerateRegion extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fy:generateRegion';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '富有：生成富有省市区';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function handle(): int
    {
//        FyRegionModel::query()->insert(json_decode('{"code":"8853","pCode":"8850","name":"呼图壁县","level":3,"regionBankCode":"8853"}', true));
//        die;


        $filePath = downloadFile(
            "https://open.fuioupay.com/downLoad.do?fileId=7c328798-da45-4a5e-bc9e-34d5b2b600cb",
            "fy",
            "fyRegion",
            "xlsx"
        );

        $this->getOutput()->info($filePath);
        Excel::import(new FyRegionImport(), $filePath);

        return 0;
    }
}
